package com.ruibang.glass.produce.controller.lh;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruibang.glass.frequencycontrol.annotation.FrequencyControl;
import com.ruibang.glass.produce.domain.req.CommonTrendChartReq;
import com.ruibang.glass.produce.domain.req.GlassCompositionReq;
import com.ruibang.glass.produce.domain.resp.GlassCompositionTrendChart;
import com.ruibang.glass.produce.entity.ProduceGlassComposition;
import com.ruibang.glass.produce.service.ProduceGlassCompositionService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;


/**
 * <p>
 * 生产-理化-玻璃成分表 前端控制器
 * </p>
 *
 * @author 宋锦康
 * @since 2024-03-11
 */
@RestController
@RequestMapping("/api/glass/produce/lh/produceGlassComposition")
@Api(value = "生产-理化-玻璃成分表控制器", tags = {"生产-理化-玻璃成分表接口"})
public class ProduceGlassCompositionController {

    @Autowired
    private ProduceGlassCompositionService produceGlassCompositionService;

    @GetMapping("/getById/{id}")
    @ApiOperation(value = "获取生产-理化-玻璃成分表", notes = "获取生产-理化-玻璃成分表")
    public ResultBody getById(@PathVariable(value = "id") String id) {
        return ResultBody.success(produceGlassCompositionService.getById(id));
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增生产-理化-玻璃成分表", notes = "新增生产-理化-玻璃成分表")
    public ResultBody save(@RequestBody ProduceGlassComposition produceGlassComposition) {
        produceGlassCompositionService.saveInfo(produceGlassComposition);
        return ResultBody.success();
    }

    @DeleteMapping("/deleteById/{id}")
    @ApiOperation(value = "通过ID删除生产-理化-玻璃成分表", notes = "通过ID删除生产-理化-玻璃成分表")
    public ResultBody delete(@PathVariable(value = "id") String id) {
        produceGlassCompositionService.delete(id);
        return ResultBody.success();
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改生产-理化-玻璃成分表", notes = "修改生产-理化-玻璃成分表")
    public ResultBody edit(@RequestBody ProduceGlassComposition produceGlassComposition) {
        produceGlassCompositionService.edit(produceGlassComposition);
        return ResultBody.success();
    }

    @PostMapping("/pageQuery")
    @ApiOperation(value = "分页列表查询生产-理化-玻璃成分表", notes = "分页列表查询生产-理化-玻璃成分表")
    public ResultBody<IPage<ProduceGlassComposition>> pageQuery(@RequestBody GlassCompositionReq glassCompositionReq) {
        return ResultBody.success(produceGlassCompositionService.pageQuery(glassCompositionReq));
    }

    @PostMapping("/trendChart")
    @ApiOperation(value = "趋势图")
    public ResultBody<GlassCompositionTrendChart> trendChart(@RequestBody CommonTrendChartReq trendChartReq) {
        return ResultBody.success(produceGlassCompositionService.trendChart(trendChartReq));
    }

    @PostMapping("/export")
    @ApiOperation(value = "数据导出")
    @FrequencyControl(time = 15, count = 2, target = FrequencyControl.Target.IP)
    @FrequencyControl(time = 30, count = 4, target = FrequencyControl.Target.IP)
    public void export(@RequestBody GlassCompositionReq glassCompositionReq, HttpServletResponse response) {
        produceGlassCompositionService.export(glassCompositionReq, response);
    }

}
